package huoye.shops.huoye.operation.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.codeideology.android.lang.entity.Paging;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import huoye.shops.base.BaseActivity;
import huoye.shops.base.PullToRefreshFragment;
import huoye.shops.huoye.operation.activity.BuildEventDetailsActivity;
import huoye.shops.huoye.operation.activity.SharePondActivity;
import huoye.shops.huoye.operation.adapter.ManageEventAdapter;
import huoye.shops.huoye.operation.model.ManageEventData;
import huoye.shops.huoye.operation.presenter.ManageEventPresenter;
import huoye.shops.huoye.operation.view.IManageEventRefreshView;


/**
 * 2018 - 08 - 12 .
 */
public class ManageEventFragment extends PullToRefreshFragment<ManageEventData> implements IManageEventRefreshView {

    public static final int TYPE_MANAGE_EVENT_START = 1; //进行中
    public static final int TYPE_MANAGE_EVENT_END = 2; //已结束


    private int mType;
    private ManageEventPresenter mManageEventPresenter;

    @Override
    public RecyclerViewAdapter createAdapter() {

        Bundle bundle = getArguments();
        mType = bundle.getInt(BaseActivity.EXTRAS_KEY_DATA);

        ManageEventAdapter adapter = new ManageEventAdapter(getActivity());
        adapter.setOnManageEventDataListener(new ManageEventAdapter.OnManageEventDataListener() {
            @Override
            public void onJoinClick(ManageEventData manageEventData) {
                //参加活动
               // manageEventData.setDetails(false);
                startActivity(SharePondActivity.class,manageEventData);

            }

            @Override
            public void onDetailsClick(ManageEventData manageEventData) {
                //详情
              //  manageEventData.setDetails(true);
                startActivity(SharePondActivity.class,manageEventData);
            }


            //自建活动
            @Override
            public void onBuildClick(ManageEventData manageEventData) {
                startActivity(SharePondActivity.class,manageEventData);
            }
        });

        return adapter;
    }

  /*  @Override
    protected void onShowFragment() {
        super.onShowFragment();
        query();

    }*/

    @Override
    public void onResume() {
        super.onResume();
        if(mManageEventPresenter != null ){
            query();
        }
    }

    @Override
    protected void initView(View view, @Nullable Bundle bundle) {
        super.initView(view, bundle);
        mManageEventPresenter = new ManageEventPresenter();
        mManageEventPresenter.addTaskListener(this);
        mManageEventPresenter.onStart();
        query();
    }


    @Override
    public void query(Paging paging) {
        super.query(paging);
        mManageEventPresenter.getEventList(mType,paging);
    }


    public static ManageEventFragment getInstan(int type) {
        ManageEventFragment fragment = new ManageEventFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(BaseActivity.EXTRAS_KEY_DATA, type);
        fragment.setArguments(bundle);
        return fragment;
    }



    @Override
    public void onItemClick(ManageEventData manageEventData, int i, View view) {

    }
}
